<template>
  <div>
    Child2
    <p>
      <button @click="onMinus">-</button>&nbsp;&nbsp;<button @click="onAdd">
        +
      </button>
    </p>
  </div>
</template>

<script>
import { mapMutations, mapActions } from 'vuex'
export default {
  methods: {
    ...mapMutations('counter', ['add']),
    ...mapActions('counter', ['asyncMinus']),
    // add(payload) {
    //   this.$store.commit('add', payload)
    // },
    // 同步
    onAdd () {
      // commit 提交
      // this.$store.commit('add', 3)
      this.add(5)
    },
    // asyncMinus (payload) {
    //   this.$store.dispatch('asyncMinus', payload)
    // },
    // 异步
    onMinus () {
      // dispatch 派发
      // this.$store.dispatch('asyncMinus', 4)
      this.asyncMinus(10)
    }
  }
}
</script>
